package com.ltg.framework.auth.api.config;

import com.ltg.framework.auth.AuthInfo;
import com.ltg.framework.auth.AuthService;
import com.ltg.framework.auth.access.filter.AccessFilter;
import com.ltg.framework.auth.access.handler.SimpleAuthAccessHandler;
import com.ltg.framework.auth.api.AuthAccessHandler;
import com.ltg.framework.auth.api.properties.LoginProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @Version 1.0
 * @Author LTG
 * @ClassName SecurityAccessConfiguration
 * @Date 2023/11/17 16:54
 */
@EnableConfigurationProperties(
        LoginProperties.class
)
public class SecurityAccessConfiguration {


    @Bean
    @ConditionalOnMissingBean(AuthAccessHandler.class)
    public AuthAccessHandler authAccessHandler(AuthService authService) {
        return new SimpleAuthAccessHandler(authService);
    }


    /**
     * 全局访问控制拦截器
     *
     * @param properties
     * @param authAccessHandler
     * @return
     */
    @Bean
    public AccessFilter accessFilter(LoginProperties properties, AuthAccessHandler authAccessHandler) {
        return new AccessFilter(properties, authAccessHandler);
    }


}
